
package com.phevos.common.dbpool;

import com.phevos.common.util.PageUtil;


public class SQLGenerator
{
    private SQLGenerator()
    {
    }

    /**
     * @��sql���ҳ��װ��
     * ����һ�������sql,ҳ�ţ�ҳ��С��
     * ���һ���ҳ��sql��䡣����sql�������Ӧ�� row_num (select rownum as row_num )
     */
    public static String pagedSql(String sql, int pageNo, int pageSize)
    {
        StringBuffer sb = new StringBuffer();
        int startRecordIndex = PageUtil.getStartIndexByPage(pageNo, pageSize);
        int endRecordIndex = PageUtil.getEndIndexByPage(pageNo, pageSize);

        sb.append("select * from (");
        sb.append(sql);
        sb.append(" ) where row_num>=" + startRecordIndex + " and row_num<=" + endRecordIndex);

        return sb.toString();
    }
}
